package com.example.studentaihouduan.Controller;

import com.example.studentaihouduan.entity.PatientRegistration;
import com.example.studentaihouduan.service.PatientRegistrationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/registrations")
@EnableCaching
public class PatientRegistrationController {

    @Autowired
    private PatientRegistrationService registrationService;

    // 获取所有挂号信息
    @GetMapping
    public List<PatientRegistration> getAllRegistrations() {
        return registrationService.getAllRegistrations();
    }

    // 根据ID获取挂号信息
    @GetMapping("/{id}")
    public PatientRegistration getRegistrationById(@PathVariable Integer id) {
        return registrationService.getRegistrationById(id);
    }

    // 创建挂号信息
    @PostMapping
    public void createRegistration(@RequestBody PatientRegistration registration) {
        registrationService.saveRegistration(registration);
    }

    // 更新挂号信息
    @PutMapping("/{id}")
    public void updateRegistration(@PathVariable Integer id, @RequestBody PatientRegistration registration) {
        registration.setId(id);
        registrationService.updateRegistration(registration);
    }

    // 删除挂号信息
    @DeleteMapping("/{id}")
    public void deleteRegistration(@PathVariable Integer id) {
        registrationService.deleteRegistration(id);
    }
}